package sort;

/**
 * 插入排序
 */
public class InsertSort {

    public static void main(String args[]){
        //输入
        int numbers[]=new int[]{5,3,2,1,7,4,9};
        int key=0;
        int j=0;
        //排序
        for (int i=1;i<numbers.length;i++){
            key=numbers[i];
            j=i-1;
            while(j>=0 && numbers[j]>key){
                numbers[j+1]=numbers[j];
                j--;
            }
            numbers[j+1]=key;
        }
        //输出
        for(int number:numbers) {
            System.out.print(number+"--");
        }
    }
}
